package com.baiqian.doupo.container;

import com.baiqian.doupo.Utils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import org.apache.logging.log4j.LogManager;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class NaJieSmallContainProvider implements INamedContainerProvider {
    private final int numSlots = 27;
    private final Inventory inventory = new Inventory(numSlots);
    private final ItemStack itemStack;

    public NaJieSmallContainProvider(ItemStack itemStack){
        this.itemStack = itemStack;
        CompoundNBT nbt = itemStack.getTag();
        if(nbt != null){
            LogManager.getLogger().info("load");
            for(int i=0;i<nbt.getInt("num");++i){
                inventory.setInventorySlotContents(nbt.getInt("where"+i),
                        ItemStack.read((CompoundNBT) nbt.get("item" + i)));
            }
        }
    }

    @Nonnull
    @Override
    public ITextComponent getDisplayName() {
        return new TranslationTextComponent(Utils.MOD_ID + ".na_jie_small_gui");
    }

    @Nullable
    @Override
    public Container createMenu(int sycID, @Nonnull PlayerInventory Playerinventory,@Nonnull PlayerEntity player) {
        return new NaJieSmallContainer(sycID, Playerinventory, inventory,itemStack);
    }
}
